package com.cnhis.cloudhealth.clidoctorweb.clischemedefine;

import java.util.Date;

import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Reference;
import com.cnhis.cloudhealth.clinical.clidoctor.clischemedefine.service.ICliSchemeDefine;
import com.cnhis.cloudhealth.commons.Mappers.ModelVo;
import com.cnhis.cloudhealth.commons.interceptor.SpringContextHolder;
import com.cnhis.cloudhealth.commons.redisdb.RedisResource;
import java.util.HashMap;

@Path("clischemedefine")
@Component
public class CliSchemeDefineRest
{
    @Reference
    private ICliSchemeDefine schemeDefine;
    private RedisResource redisResource = (RedisResource) SpringContextHolder.getBean("redisResource");
    /* ScriptId(170) */
    /* Description(药品目录分类查询) */
    @GET
    @Path("catalog")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo catalog()
        throws Exception
    {
        return schemeDefine.catalog();
    }
    
    /* ScriptId(1488) */
    /* Description(成套方案定义中检索分类对应方案项目) */
    /**
     * 
     * @param lBCE01 员工id
     * @param lBCK01 部门id
     * @param lBDO01 医疗项目分类id
     * @param edate
     * @param currPage
     * @param pageSize
     * @return
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    @POST
    @Path("querycatalogitem")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo queryCatalogItem(@FormParam("lBCE01") int lBCE01, @FormParam("lBCK01") int lBCK01,
        @FormParam("lBDO01") int lBDO01, @FormParam("edate") String edate, @FormParam("currPage") int currPage,
        @FormParam("pageSize") int pageSize)
        throws Exception
    {
        HashMap map = new HashMap();
        map.put("lBCK01", lBCK01);
        map.put("lBDO01", lBDO01);
        map.put("edate", edate);
        return schemeDefine.queryCatalogItem(map, (currPage - 1) * pageSize, pageSize);
    }
    
    /* ScriptId(1107) */
    /* Description(治疗方案组成明细) */
    /**
     * 
     * @param lBBX01A 医疗项目id
     * @param lACF01 业务分类id
     * @param lCheck
     * @param lDate
     * @return
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    @POST
    @Path("schemedetail")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo schemeDetail(@FormParam("lBBX01A") int lBBX01A, @FormParam("lACF01") int lACF01,
        @FormParam("lCheck") int lCheck, @FormParam("lDate") String lDate, @FormParam("currPage") int currPage,
        @FormParam("pageSize") int pageSize)
        throws Exception
    {
        HashMap map = new HashMap();
        map.put("lBBX01A", lBBX01A);
        map.put("lACF01", lACF01);
        map.put("lCheck", lCheck);
        map.put("lDate", lDate);
        return schemeDefine.schemeDetail(map, (currPage - 1) * pageSize, pageSize);
    }
    
    /* ScriptId(1489) */
    /* Description(全局检索分类方案项目) */
    /**
     * 
     * @param lBCE01 员工id
     * @param lBCK01 科室id
     * @param lTxt 搜索关键字
     * @return
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    @POST
    @Path("allsearch")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo allSearch(@FormParam("lBCE01") int lBCE01, @FormParam("lBCK01") int lBCK01,
        @FormParam("lTxt") String lTxt, @FormParam("currPage") int currPage, @FormParam("pageSize") int pageSize)
        throws Exception
    {
        HashMap map = new HashMap();
        map.put("lBCE01", lBCE01);
        map.put("lBCK01", lBCK01);
        map.put("lTxt", lTxt + "%");
        return schemeDefine.allSearch(map, (currPage - 1) * pageSize, pageSize);
    }
    
    /* ScriptId(1492) */
    /* Description(成套方案定义中检索临床科室) */
    @GET
    @Path("queryOffice")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo queryOffice()
        throws Exception
    {
        return schemeDefine.queryOffice();
    }
    
    /* ScriptId(1494) */
    /* Description(治疗方案别名) */
    /**
     * 
     * @param BDK06 诊疗项目类型
     * @param BBX01 诊疗项目id
     * @return
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    @POST
    @Path("schemealias")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo schemeAlias(@FormParam("BDK06") int BDK06, @FormParam("BBX01") int BBX01)
        throws Exception
    {
        HashMap map = new HashMap();
        map.put("BDK06", BDK06);
        map.put("BBX01", BBX01);
        return schemeDefine.schemeAlias(map);
    }
    
    /* ScriptId(717) */
    /* Description(树形左边列表：医嘱编辑窗口检索医嘱项目) */
    @GET
    @Path("adviceitemtree")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo adviceItemTree()
        throws Exception
    {
        return schemeDefine.adviceItemTree();
    }
    
    /* ScriptId(1650) */
    /* Description(树形：用于治疗方案检索药品) */
    /**
     * 
     * @param lACF01 业务id
     * @param lBDO01 医疗项目分类id
     * @param lSqlText 搜索关键字
     * @param lBDA01 医疗项目类别
     * @param lDate
     * @return
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    @POST
    @Path("getmedical")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo getMedical(@FormParam("lACF01") int lACF01, @FormParam("lBDO01") int lBDO01,
        @FormParam("lSqlText") String lSqlText, @FormParam("lBDA01") String lBDA01, @FormParam("lDate") String lDate,
        @FormParam("currPage") int currPage, @FormParam("pageSize") int pageSize)
        throws Exception
    {
        HashMap map = new HashMap();
        map.put("lBDO01", lBDO01);
        map.put("lSqlText", lSqlText + "%");
        map.put("lBDA01", lBDA01);
        map.put("lDate", lDate);
        return schemeDefine.getMedical(map, (currPage - 1) * pageSize, pageSize);
    }
    
    /* ScriptId(757) */
    /* Description(临嘱 树形： 诊疗 检索医嘱分类对应的明细项目) */
    /**
     * 
     * @param lBDO01 医疗项目分类
     * @param lACF01 业务
     * @param lSql
     * @param lBBX09 执行频率
     * @param abc02 病人费别名称
     * @param bdp02 病人类别
     * @param lBCE01 员工id
     * @param lBCK01 科室id
     * @param lDate YYYY-MM-DD
     * @param gparam60
     * @param currPage
     * @param pageSize
     * @return
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    @POST
    @Path("catalogdetail")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo catalogDetail(@FormParam("lBDO01") int lBDO01, @FormParam("lACF01") int lACF01,
        @FormParam("lSql") String lSql, @FormParam("lBBX09") int lBBX09, @FormParam("abc02") String abc02,
        @FormParam("bdp02") String bdp02, @FormParam("lBCE01") int lBCE01, @FormParam("lBCK01") int lBCK01,
        @FormParam("lDate") String lDate, @FormParam("gparam60") String gparam60, @FormParam("currPage") int currPage,
        @FormParam("pageSize") int pageSize)
        throws Exception
    {
        HashMap map = new HashMap();
        map.put("lBDO01", lBDO01);
        map.put("lSql", lSql + "%");
        map.put("lACF01", lACF01);
        map.put("lDate", lDate);
        
        map.put("lBBX09", lBBX09);
        map.put("abc02", abc02);
        map.put("bdp02", bdp02);
        map.put("lBCE01", lBCE01);
        map.put("lBCK01", lBCK01);
        map.put("gparam60", gparam60);
        return schemeDefine.catalogDetail(map, (currPage - 1) * pageSize, pageSize);
    }
    
    /* ScriptId(7367) */
    /* Description(获取医疗项目参考提示) */
    /**
     * 
     * @param ltype
     * @param bbx01 医疗项目id
     * @return
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    @POST
    @Path("medicalprompt")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo medicalPrompt(@FormParam("ltype") int ltype, @FormParam("bbx01") int bbx01
    
    )
        throws Exception
    {
        HashMap map = new HashMap();
        map.put("ltype", ltype);
        map.put("bbx01", bbx01);
        return schemeDefine.medicalPrompt(map);
    }
    
    /* ScriptId(1686) */
    /* Description(下达医嘱时，提取治疗) */
    /**
     * 
     * @param lBBX01A --治疗方案id
     * @param lACF01 --业务id
     * @param lCheck
     * @param lBCK01 --科室id
     * @param BCKyf
     * @param bdp02 --病人类别
     * @param abc02 --病人费别名称
     * @param lDate 日期 YYYY-MM-DD
     * @param aParamno
     * @param para359_395
     * @return
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    @POST
    @Path("fetchtreatment")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo fetchTreatment(@FormParam("lBBX01A") long lBBX01A, @FormParam("lACF01") int lACF01,
        @FormParam("lCheck") int lCheck, @FormParam("lBCK01") int lBCK01, @FormParam("BCKyf") int BCKyf,
        @FormParam("bdp02") String bdp02, @FormParam("abc02") String abc02, @FormParam("lDate") String lDate
    
    )
        throws Exception
    {
        HashMap map = new HashMap();
        map.put("lBBX01A", lBBX01A);
        map.put("lACF01", lACF01);
        map.put("lCheck", lCheck);
        map.put("lBCK01", lBCK01);
        map.put("BCKyf", BCKyf);
        map.put("bdp02", bdp02);
        map.put("abc02", abc02);
        map.put("lDate", new Date());
        return schemeDefine.fetchTreatment(map);
    }
    
    /* ScriptId(7303) */
    /* Description(下达草药医嘱，草药常用项目列表) */
    /**
     * 
     * @param lBCE01 员工id
     * @param lBCK01 开单科室
     * @param lDate
     * @param aACF01
     * @param aParamno
     * 
     * @return
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    @POST
    @Path("herbcommonuselist")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo herbCommonUseList(@FormParam("lBCE01") int lBCE01, @FormParam("lBCK01") int lBCK01,
        @FormParam("lDate") String lDate, @FormParam("aACF01") int aACF01, @FormParam("aParamno") String aParamno
    
    )
        throws Exception
    {
        HashMap map = new HashMap();
        map.put("lBCK01", lBCK01);
        map.put("lDate", lDate);
        map.put("aACF01", aACF01);
        map.put("aParamno", aACF01);
        return schemeDefine.herbCommonUseList(map);
    }
    
    /* ScriptId(676) */
    /* Description(中药煎法) */
    /**
     * 
     * @param lBDA01 医疗类别
     * @param lBBX13 医疗项目执行形式
     * @param aDate 日期
     * @return
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    @POST
    @Path("findspecialtreament")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo findSpecialTreament(@FormParam("lBDA01") String lBDA01, @FormParam("lBBX13") String lBBX13,
        @FormParam("aDate") String aDate)
        throws Exception
    {
        
        //加载redis数据
//        return redisResource.getRedisModelVo("bbx1_zhongyaojianfa_mz");
        //从数据库加载
        HashMap map = new HashMap();
        map.put("lBDA01", lBDA01);
        map.put("lBBX13", lBBX13);
        map.put("aDate", aDate);
        return schemeDefine.findSpecialTreament(map);
    }
    
    /* ScriptId(799) */
    /* Description(中草药：根据id查询草药) */
    /**
     * 
     * @param lBBY01 收费项目id
     * @param adate 有效期
     * @return
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    @POST
    @Path("getherbbyid")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo getHerbById(@FormParam("lBBY01") int lBBY01, @FormParam("adate") String adate)
        throws Exception
    {
        HashMap map = new HashMap();
        map.put("lBBY01", lBBY01);
        map.put("adate", adate);
        return schemeDefine.findSpecialTreament(map);
    }
    
    /* ScriptId(339) */
    /* Description(判断药品品种编码是否重复) */
    /**
     * 
     * @param lBBX04 药品品种编码
     * @return
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    @GET
    @Path("checkcode")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo checkCode(@QueryParam("lBBX04") String lBBX04)
        throws Exception
    {
        HashMap map = new HashMap();
        map.put("lBBX04", lBBX04);
        return schemeDefine.checkCode(map);
    }
    
    // Clinic_BEF1_Insert
    // 新增方案
    /**
     * 
     * @param lxml 医疗项目目录 诊疗项目 诊疗方案 诊疗应用
     * @param lMode
     * @param lBBX01 方案id
     * @param lACF01 0:新增 1：修改
     * @param lBCE01 员工id
     * @return
     * @throws Exception
     * 
     */
    @SuppressWarnings("unchecked")
    @POST
    @Path("clinicbef1insert")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo clinicBEF1Insert(@FormParam("lxml") String lxml, @FormParam("lMode") int lMode,
        @FormParam("lBBX01") int lBBX01, @FormParam("lACF01") int lACF01, @FormParam("lBCE01") int lBCE01)
        throws Exception
    {
        HashMap map = new HashMap();
        map.put("lxml", lxml);
        map.put("lMode", lMode);
        map.put("lBBX01", lBBX01);
        map.put("lACF01", lACF01);
        map.put("lBCE01", lBCE01);
        return schemeDefine.clinicBEF1Insert(map);
    }
    
    // Clinic_BBX_DEL
    // 删除方案
    /**
     * 
     * @param BBX01 方案id
     * @return
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    @GET
    @Path("clinicbbxdel")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo clinicBBXDEL(@QueryParam("lBBX01") Long lBBX01)
        throws Exception
    {
        HashMap map = new HashMap();
        map.put("lBBX01", lBBX01);
        return schemeDefine.clinicBBXDEL(map);
    }
    
    /**
     * 根据治疗方案获取医嘱详细--中药医嘱（方剂：bda01='8'）
     * 
     * @return
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    @GET
    @Path("getVaf1Bybbx01a_8")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo getVaf1Bybbx01a_8(@QueryParam("bbx01a") long bbx01a)
        throws Exception
    {
        HashMap map = new HashMap();
        map.put("bbx01a", bbx01a);
        return schemeDefine.getVaf1Bybbx01a_8(map);
    }
    
    /**
     * 根据治疗方案获取医嘱详细--手术医嘱（方剂：bda01='S'）
     * 
     * @return
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    @GET
    @Path("getVaf1Bybbx01a_s")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo getVaf1Bybbx01a_s(@QueryParam("bbx01a") long bbx01a)
        throws Exception
    {
        HashMap map = new HashMap();
        map.put("bbx01a", bbx01a);
        return schemeDefine.getVaf1Bybbx01a_s(map);
    }
    
    /**
     * ScriptId(1455) 根据首字母检索对应类型医嘱
     * 
     * @return
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    @GET
    @Path("adviceSousuo")
    @Produces({MediaType.APPLICATION_JSON})
    public ModelVo adviceSousuo(@QueryParam("sqltext") String sqltext,
                                @QueryParam("acf01") int acf01,
                                @QueryParam("bbx09") int bbx09,
                                @QueryParam("beh01") String beh01,
                                @QueryParam("bck01") int bck01,
                                @QueryParam("bce01") int bce01,
                                @QueryParam("bckyf") int bckyf,
                                @QueryParam("abc02") String abc02,
                                @QueryParam("bdp02") String bdp02,
                                @QueryParam("vaf58") int vaf58,
                                @QueryParam("yiyuanId") int yiyuanId,
                                @QueryParam("offset") int offset
                                )
        throws Exception
    {
        HashMap map = new HashMap();
        map.put("sqltext", sqltext);
        map.put("acf01", acf01);
        map.put("bbx09", bbx09);
        map.put("beh01", beh01);
        map.put("bck01", bck01);
        map.put("bce01", bce01);
        map.put("bckyf", bckyf);
        map.put("abc02", abc02);
        map.put("bdp02", bdp02);
        map.put("vaf58", vaf58);
        map.put("yiyuanId", yiyuanId);
        map.put("offset", offset);
        return schemeDefine.adviceSousuo(map);
    }
}
